
package jwww.ml;

import org.w3c.dom.*; 

public class XHTML
{
  Document document = null; 

  Element head  = null;
  Element title = null;
  Element body  = null; 
  
  public XHTML()
  {
    document = XML.blank();
    Element html  = XML.add(document, "html");
    head  = XML.add(html, "head"); 
    title = XML.add(head, "title");
    body  = XML.add(html, "body");
  }

  public void title(String title)
  {
    XML.set(this.title, title); 
  }

  public Element center()
  {
    return center(body); 
  }

  public Element center(Element point)
  {
    return XML.add(point, "center"); 
  }

  public Element center(Element point, String text)
  {
    return XML.add(point, "center", text); 
  }

  public Element p(Element point, String text)
  {
    return XML.add(point, "p", text); 
  }
  
  public Element p(String text)
  {
    return XML.add(body, "p", text); 
  }

  public Element link(Element point, String text, String href)
  {
    Element link = XML.add(point, "a", text);
    link.setAttribute("href", href); 
    return link; 
  }
  
  public Element table(Element point, int border)
  {
    Element table = table(point);
    table.setAttribute("border", "" + border);
    return table; 
  }
  
  public Element table(Element point)
  {
    return XML.add(point, "table"); 
  }
  
  public Element table()
  {
    return table(body);
  }
  
  public Element tr(Element table)
  {
    return XML.add(table, "tr"); 
  }

  public Element td(Element tr, int colspan)
  {
    Element td = XML.add(tr, "td");
    td.setAttribute("colspan", "" + colspan);
    return td; 
  }

  public Element td(Element tr, String text)
  {
    return XML.add(tr, "td", text); 
  }
  
  public Element td(Element tr)
  {
    return XML.add(tr, "td"); 
  }

  public Element b(Element point, String text)
  {
    return XML.add(point, "b", text);
  }

  public Element tt(Element point, String text)
  {
    return XML.add(point, "tt", text);
  }
  
  public Element h3(Element point, String text)
  {
    return XML.add(point, "h3", text);
  }
  
  public Element h3(Element point)
  {
    return XML.add(point, "h3"); 
  }

  public Element green(Element point, String text)
  {
    Element font = XML.add(point, "font", text);
    font.setAttribute("color", "green"); 
    return font; 
  }

  public void br(Element point)
  {
    XML.add(point, "br"); 
  }
  
  public Element form(Element point, String action)
  {
    Element form = XML.add(point, "form");
    form.setAttribute("action", action);
    return form; 
  }

  public Element input(Element point, String name)
  {
    Element input = XML.add(point, "input");
    input.setAttribute("name", name); 
    return input; 
  }

  public Element submit(Element point, String value)
  {
    Element input = XML.add(point, "input");
    input.setAttribute("type", "submit"); 
    input.setAttribute("value", value); 
    return input; 
  }

  public void redirect(int time, String target)
  {
    Element meta = XML.add(head, "meta");
    meta.setAttribute("http-equiv", "refresh");
    meta.setAttribute("content", "" + time + " URL=" + target); 
  }
  
  public String toString()
  {
    return XML.string(document); 
  }
}

